from DrissionPage import ChromiumPage, ChromiumOptions
import time
from datetime import datetime, timedelta
from pprint import pprint
import json
import logging as log

log.basicConfig(level=log.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')

upList = []
# 米哈游
upList.append({"1964759150": "白毛大彩笔"})
# 时政
upList.append({"703186600": "麻薯波比呀"})
upList.append({"430426421": "燕三嘤嘤嘤"})
upList.append({"546189": "小Q不是导盲犬"})
upList.append({"397490386": "肝帝董佳宁"})
# 军事
upList.append({"1975692083": "军情巴朗"})
# 科技
upList.append({"4401694": "林亦LYi"})
# 动漫
upList.append({"14546601": "Muc虚空之翼"})


co1 = ChromiumOptions().set_local_port(9222).set_user_data_path(r'D:\data\drissionpage\9222')
page = ChromiumPage(co1)

def main():
    urlList = ["https://space.bilibili.com/"+list(item.keys())[0]+"/video" for item in upList]

    # 获取今天的日期和时间，并设置为零点
    today = datetime.now().date()
    midnight = datetime.combine(today, datetime.min.time())
    # 转换为时间戳
    timestamp = midnight.timestamp()

    for url in urlList[0:1]:
        log.info(url)
        page.listen.start('/space/wbi/arc/search')
        page.get(url)
        packet = page.listen.wait()  # 等待数据包
        vlist = packet.response.body['data']['list']['vlist']
        for item in vlist:
            info = {}
            info['title'] = item['title']
            info['bv'] = item['bvid']
            info['description'] = item['description']
            info['length'] = item['length']
            info['created'] = item['created']
            info['created_str'] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(item['created']))
            info['today'] = timestamp
            pprint(info)
        time.sleep(1)


if __name__ == '__main__':
    main()
